﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BangleCMS.Model;
using BangleCMS.BLL;
using System.Data;
using System.Linq;


public partial class newslist : WebPageBase
{
    t_webnavBLL nav_bll = new t_webnavBLL();

    #region 属性
    private DataTable _dt_list;
    /// <summary>
    /// 用于传数据台页面
    /// </summary>
    public DataTable dt_list
    {
        get
        {
            return _dt_list;
        }
        set
        {
            _dt_list = value;
        }
    }

    public string NewsTypeCode
    {
        get
        {
            return base.ParseQueryString("t", "");
        }
    }

    private t_webnav _getleftwebnav;
    public t_webnav GetLeftWebnav
    {
        get
        {
            if (_getleftwebnav == null)
            {
                t_webnav nav = nav_bll.GetModelList(string.Format(" Code='{0}' ", NewsTypeCode)).FirstOrDefault();
                if (nav == null)
                {
                    return new t_webnav();
                }
                _getleftwebnav = nav;

            }
            return _getleftwebnav;
        }
    }
    #endregion

    #region 共用方法
    public string GetNewsDetailUrl(string code, int id)
    {
        return string.Format("/news/{0}/{1}.shtml", code, id);
    }
    #endregion

    #region 分页用到的属性
    private int _pageindex = 0;
    private int _pagecount = 0;
    private int _pagesize = 15;
    private int _datecount = 0;
    public int PageIndex
    {
        set { _pageindex = value; }
        get { return _pageindex; }
    }

    public int PageCount
    {
        set { _pagecount = value; }
        get { return _pagecount; }
    }

    public int PageSize
    {
        set { _pagesize = value; }
        get { return _pagesize; }
    }

    public int DataCount
    {
        set { _datecount = value; }
        get { return _datecount; }
    }
    #endregion

    #region 加载
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetDate();
        }
    }
    #endregion

    #region 获得数据
    private void GetDate()
    {
        UtilityBLL bll = new UtilityBLL();

        string swhere = " Valid=1 ";
        if (NewsTypeCode.ToLower() != "news")
        {
            swhere += string.Format(" and NewsType='{0}' ", NewsTypeCode);
        }

        //分页
        PageIndex = base.ParseQueryInt("p", 1);
        PageSize = 20;
        DataCount = bll.GetRecordCount("t_news", swhere);
        PageCount = (DataCount - 1) / PageSize + 1;

        //数据绑定
        DataSet ds = new DataSet();
        ds = bll.GetListByPage("t_news", "*", swhere, "ReleaseDate", 0, PageIndex, PageSize);
        dt_list = ds.Tables[0];
    }
    #endregion
}
